
'use strict';

/**
	Part of Zombie Navigator
	Copyright © 2015  Zombie Navigator Developers
	
	@file
	@module
	@license AGPL-3.0+
*/


/* Internal properties */

/**
	Where the pseudo-modules are located
	Loading modules from outside this prefix is not allowed
	@private
*/
const _modulePrefix = '../api/';

/**
	Map from a virtual module id into the physical id
	@private
*/
const _resolveID = virtualID => _modulePrefix + virtualID;


/* Exported APIs */

/**
	Load (pseudo-)modules to use with a Zombie script
	This can only be used to load modules in _modulePrefix
	@public
*/
const loadModules = function (moduleIDs) {
	moduleIDs = Array.from(moduleIDs);
	
	const modules = Object.create(null);
	
	for (let i of moduleIDs) {
		i = i + '';
		if (-1 !== i.indexOf('.') || -1 !== i.indexOf('//') || -1 !== i.indexOf(':')) {
			// contains '.', '//' or ':'; ignore it
			continue;
		}
		
		const resolvedID = _resolveID(i);
		modules[i] = require(resolvedID); // use of require ()
	}
	
	return modules;
};


/*
	Exports
*/
exports.loadModules = loadModules;


// vim: ts=4 noet ai

